<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>存款信息更新 - 管理后台</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Microsoft YaHei', Arial, sans-serif;
        }

        body {
            min-height: 100vh;
            background: linear-gradient(135deg, #e0e7ff 0%, #f5f7fa 100%);
            display: flex;
            justify-content: center;
            align-items: center;
            padding: 20px;
        }

        .container {
            width: 100%;
            max-width: 500px;
            margin: 20px auto;
            animation: fadeIn 0.5s ease;
        }

        .card {
            background: #fff;
            border-radius: 16px;
            box-shadow: 0 5px 20px rgba(0, 0, 0, 0.10);
            padding: 40px 36px 32px 36px;
            position: relative;
            border-top: 4px solid #1a3a6c;
        }

        h2 {
            color: #1a3a6c;
            text-align: center;
            margin-bottom: 30px;
            font-size: 26px;
            font-weight: 700;
            position: relative;
            padding-bottom: 15px;
        }

        h2:after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 50%;
            transform: translateX(-50%);
            width: 80px;
            height: 3px;
            background: linear-gradient(90deg, #1a3a6c, #2e6bc6);
            border-radius: 3px;
        }

        .section-title {
            font-size: 22px;
            color: #1a3a6c;
            margin-bottom: 28px;
            padding-bottom: 12px;
            border-bottom: 2px solid #1a3a6c;
            display: flex;
            align-items: center;
            gap: 12px;
        }

        .section-title i {
            color: #1a3a6c;
            font-size: 22px;
        }

        .form-group {
            margin-bottom: 28px;
        }

        .form-group label {
            display: block;
            margin-bottom: 10px;
            font-weight: 600;
            color: #444;
            font-size: 16px;
        }

        .form-group input {
            width: 100%;
            padding: 15px;
            border: 1px solid #ddd;
            border-radius: 8px;
            font-size: 16px;
            transition: all 0.3s;
        }

        .form-group input:focus {
            border-color: #1a3a6c;
            box-shadow: 0 0 0 3px rgba(26, 58, 108, 0.08);
            outline: none;
        }

        .form-group input::placeholder {
            color: #a0aec0;
            font-size: 14px;
        }

        .btn-primary {
            width: 100%;
            padding: 15px;
            border-radius: 8px;
            font-size: 18px;
            font-weight: 600;
            cursor: pointer;
            border: none;
            background: #1a3a6c;
            color: #fff;
            transition: all 0.3s;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 10px;
            box-shadow: 0 2px 8px rgba(26, 58, 108, 0.10);
        }

        .btn-primary:hover {
            background: #15315a;
            transform: translateY(-2px);
            box-shadow: 0 5px 15px rgba(26, 58, 108, 0.18);
        }

        .btn-primary:disabled {
            opacity: 0.6;
            cursor: not-allowed;
            transform: none;
        }

        .result-card {
            margin-top: 24px;
            background: #f8f9fa;
            border-left: 4px solid #1a3a6c;
            border-radius: 8px;
            padding: 18px 20px;
            font-size: 15px;
            color: #1a3a6c;
            box-shadow: 0 2px 8px rgba(26, 58, 108, 0.06);
            display: none;
            align-items: center;
            gap: 10px;
        }

        .result-card.success {
            border-left-color: #2ecc71;
            color: #2ecc71;
        }

        .result-card.error {
            border-left-color: #e74c3c;
            color: #e74c3c;
        }

        .result-card i {
            font-size: 18px;
        }

        .loading {
            width: 16px;
            height: 16px;
            border: 2px solid #ffffff;
            border-top: 2px solid transparent;
            border-radius: 50%;
            animation: spin 1s linear infinite;
        }

        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }

        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(10px); }
            to { opacity: 1; transform: translateY(0); }
        }

        .input-icon {
            position: absolute;
            right: 15px;
            top: 38px;
            color: #a0aec0;
            font-size: 16px;
        }

        .card-footer {
            margin-top: 30px;
            text-align: center;
            font-size: 13px;
            color: #718096;
            padding-top: 15px;
            border-top: 1px solid #edf2f7;
        }

        @media (max-width: 576px) {
            .card {
                padding: 25px 20px;
            }

            h2 {
                font-size: 22px;
                margin-bottom: 25px;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="card">
            <h2>存款信息更新</h2>

            <div class="section-title">
                <i class="fa fa-edit"></i>存款信息更新
            </div>

            <div class="form-group">
                <label for="update-depositId">存款ID</label>
                <input id="update-depositId" type="number" placeholder="请输入存款ID（必填）">
            </div>

            <div class="form-group">
                <label for="update-depositName">存款类型名称</label>
                <input id="update-depositName" type="text" placeholder="请输入新的存款类型名称">
            </div>

            <div class="form-group">
                <label for="update-depositDesc">描述</label>
                <input id="update-depositDesc" type="text" placeholder="请输入新的描述">
            </div>

            <button class="btn-primary" id="update-btn" onclick="updateDeposit()">
                <i class="fa fa-save"></i>更新存款类型
            </button>

            <div class="result-card" id="update-result">
                <i class="fa"></i>
                <span id="update-result-text"></span>
            </div>
        </div>
    </div>

    <script>
        function updateDeposit() {
            const depositId = document.getElementById('update-depositId').value.trim();
            const depositName = document.getElementById('update-depositName').value.trim();
            const depositDesc = document.getElementById('update-depositDesc').value.trim();
            
            // 前端验证
            if (!depositId) {
                showUpdateResult({code: 'error', message: '请输入存款ID！'});
                return;
            }
            
            // 显示加载状态
            const button = document.getElementById('update-btn');
            const originalText = button.innerHTML;
            button.innerHTML = '<div class="loading"></div>处理中...';
            button.disabled = true;
            
            // 构建URL参数
            const params = new URLSearchParams();
            params.append('savingID', depositId);
            if (depositName) params.append('savingName', depositName);
            if (depositDesc) params.append('descrip', depositDesc);
            
            fetch(`http://localhost:8080/admin/deposit/update?${params.toString()}`, {
                method: 'PUT',
                headers: { 'Content-Type': 'application/json' }
            })
            .then(r => r.json())
            .then(d => {
                showUpdateResult(d);
                button.innerHTML = originalText;
                button.disabled = false;
            })
            .catch(e => {
                showUpdateResult({
                    code: 'error',
                    message: '网络请求失败，请稍后重试'
                });
                button.innerHTML = originalText;
                button.disabled = false;
            });
        }

        function showUpdateResult(d) {
            const card = document.getElementById('update-result');
            const text = document.getElementById('update-result-text');

            if (d.code === '200') {
                card.className = 'result-card success';
                card.querySelector('i').className = 'fa fa-check-circle';
                text.innerText = '存款类型更新成功！';
                
                // 清空表单
                document.getElementById('update-depositName').value = '';
                document.getElementById('update-depositDesc').value = '';
            } else {
                card.className = 'result-card error';
                card.querySelector('i').className = 'fa fa-times-circle';
                text.innerText = d.message || '更新失败，请重试';
            }

            card.style.display = 'flex';

            // 5秒后自动隐藏结果提示
            setTimeout(() => {
                card.style.display = 'none';
            }, 5000);
        }
    </script>
</body>
</html>